package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainManager;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * author:z
 * time:2021/12/29 11:45
 * description:
 */
@Component
@RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)
@Slf4j
public class StandartSumbitListener {

    @Autowired
    private FilterChainManager filterChainManager;

    @RabbitHandler
    public void messageHandler(StandardSubmit standardSubmit, Channel channel, Message message){
        log.info("[策略模块-StandartSumbitListener监听器],策略开始执行！");
        //1，调用责任链模式接口
        boolean flag = filterChainManager.executeFilter(standardSubmit);
        //2.根据处理结果返回ack
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("[策略模块-StandartSumbitListener监听器],策略执行结束！");
    }
}
